<?php
    include_once("../action/checkAuthenticationAction.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Danh sách khách hàng</title>
	<?php 
        include("import-css.php");
        include("../util/constant.php");
        include("../util/message.php");
    ?>
    
</head>
<body>
	<?php include("header.php");?>
<form id="form" method="post">
	<div class="container-fluid">
		<div class="row-fluid">
			<?php 
                include("menu.php");
                include_once("../service/userService.php");
            ?>
			<div id="content" class="span10">
                <div id="msg" class="center alert"></div>
                <div class="row-fluid sortable">
    				<div class="box span12">
                    	<div class="box-header well" data-original-title>
                        	<form id="form" target="_blank">
                                <button type="button" class="btn btn-primary" onClick="submitForm('form', '../action/exportUserAction.php', 'post')">
                                    <i class="icon-edit icon-white"></i>Xuất excel
                                </button>
                            </form>
    					</div>
    					<div class="box-content">
                            
                            <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                <thead>
                                    <tr>
                                        <th>STT</th>
                                        <th>Tên</th>
                                        <th>Email</th>
                                        <th>Địa chỉ</th>
                                        <th>Số điện thoại</th>
                                        <th>Trạng thái</th>
                                        <th>Chức năng</th>
                                    </tr>
                                 </thead>   
                                 <tbody>
                                 	<?php

										
										$customers = findUsersToExport();
										$count = 1;
										
										while($row = mysql_fetch_array($customers)){											
                                    ?>
                                        <tr id="row<?php echo $count;?>">
                                            <td><?php echo $count;?></td>
                                            <td><?php echo $row["USER_FULLNAME"];?></td>
                                            <td><?php echo $row["USER_EMAIL"];?></td>
                                            <td><?php echo $row["USER_ADDRESS"];?></td>
                                            <td><?php echo $row["USER_PHONENUMBER"];?></td>
                                            <td><?php echo $row["STATUS"];?></td>
                                            <td>
                                            	<select name="status" onChange="changeCustomerStatus(<?php echo $row["USER_ID"];?>, this.value);">
                                                	<option value="1" <?php echo ($row["USER_STATUS"]== 1) ? "selected='selected'": ""?>>Hoạt động</option>
                                                    <option value="0" <?php echo ($row["USER_STATUS"]== 0) ? "selected='selected'": ""?>>Bị khóa</option>
                                                </select>
                                            </td>
                                        </tr>
                                    <?php
										}
                                    ?>
                                 </tbody>
                             </table>    
    					</div>
    				</div><!--/span-->
    			</div><!--/row-->
            </div><!-- end of content -->
        </div><!-- end of row-fluid -->
        <?php include("footer.php");?>
    </div><!-- container-fluid -->
    <?php include("import-js.php");?>
    <script>
		function changeCustomerStatus(userId, status){
			$.ajax({  
                type: "POST",  
                url: "../action/ajax/editUserStatusAction.php",  
                data: "userId=" +  userId + "&status=" + status,
                success: function(data) {
                    if(data == <?php echo UPDATE_SUCCESSFULLY;?>){
                        showMessage("<?php echo $messages["updateUserStatusSuccessfully"];?>", "success");
						$("#" + rowId).remove();
                    } else{
                        showMessage("<?php echo $messages["updateUserStatusFailed"];?>", "error");
                    }
                }
            });
		}
	</script>
</form>
</body>
</html>